package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.pojo.Order;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {

    @Autowired
    private MemberDao memberDao;

    @Autowired
    private OrderDao orderDao;

    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        //获取当天日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());
        //获取本周一日期
        String  thisWeekMonday= DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //获取本月第一天日期
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //得到会员数据统计
        Map<String,Integer> map = memberDao.findOrderCountByDate(today,thisWeekMonday,firstDay4ThisMonth);
        //预约到诊数据统计
        Map<String,Integer> mapOrder = orderDao.findVisitsCount(today,thisWeekMonday,firstDay4ThisMonth);
        //热门套餐
        List<Map> hotSetmeal = orderDao.findHotSetmeal();

        Map<String,Object> result = new HashMap<>();
        result.put("member",map);
        result.put("order",mapOrder);
        result.put("hotSetmeal",hotSetmeal);
        return result;
    }
}
